<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico" >
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.js"></script>
    <script type="text/javascript" src="../js/respond.min.js"></script>
    <![endif]-->
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../css/H-ui.css" />
    <link rel="stylesheet" type="text/css" href="../css/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../css/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <title></title>

</head>
<body>
<article class="page-container userUpdate">
    <form action="" method="post" class="form form-horizontal" id="form-user-add">
        <input type="hidden" id="userIdChild" user-id-child= "" data-iftrue=""/>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="selectbox">
                    <div class="select-bar" style="display: none">
                        <select multiple="multiple" id="select1">
                            <!--<option value="超级管理员">超级管理员</option>
                            <option value="普通管理员">普通管理员</option>
                            -->
                        </select>
                    </div>
                    <div class="select-bar">
                        <select multiple="multiple" id="roles"></select>
                    </div>

                </div>
            </div>
        </div>

    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../js/H-ui.js"></script>
<script type="text/javascript" src="../js/H-ui.min.js"></script>
<script type="text/javascript" src="../js/postJson.js"></script>
<script type="text/javascript" src="../js/root.js"></script>
<script type="text/javascript" src="../js/jquery.validation/jquery.validate.js"></script>
<script type="text/javascript" src="../js/jquery.validation/validate-methods.js"></script>
<script type="text/javascript" src="../js/jquery.validation/messages_zh.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript">
/*页面初始化*/
function updataEdie(){
    //获取父窗口roleId
    var userId =  Number(parent.$("#query").attr("data-userid"))
    var superM=  Number(parent.$("#query").attr("data-iftrue"))

    $("#userIdChild").attr("user-id-child",userId)
    $("#userIdChild").attr("data-iftrue",superM)
    var dataCollect="id="+Number(userId);
    dataCollect= decodeURIComponent(dataCollect,true);//防止中文乱码
    var jsondata=strJSON.formToJson(dataCollect);//转化为json
    var url = "/sysUser/queryOneByUserId";
    $.ajax({
        url:url,
        contentType:"application/json",
        data:jsondata,
        type:"post",
        async:false,
        dataType:'json',
        success:function(msg){
            if(msg.success) {
                if($("#userIdChild").attr("data-iftrue")==0){
                   // console.log(JSON.stringify(msg.data))
                    var roleIds = [];
                    for(var key in msg.data.roleIds){
                        roleIds.push(Number(msg.data.roleIds[key].roleId))
                    }

                    var htmlString = '';
                    $.each(msg.data.flag,function(i,n){
                        htmlString += '<option value="'+ n.name+'" roleId="'+ n.id+'">'+ n.name+'</option>'
                    })
                    $("#select1").append(htmlString)
                    $("#select1 option").each(function(i){
                        for(var j=0;j<$("#select1 option").length;j++){
                            if(Number($(this).attr("roleid"))==roleIds[j]){
                                $("#roles").append("<option data-add='"+i+"'>"+$("#select1").find("option").eq(i).val()+"</option>")
                            }
                        }

                    })
                }else{
                    var htmlString = '<option value="超级管理员" >超级管理员</option>'
                    $("#roles").append(htmlString)
                }
            }else {
                var error = msg.errorMessage;
                parent.layer.msg(error,{icon:2,time:3000});
            }
        },
        error:function(XMLHttpRequest,textStatus,errorThrown){
            var XmlStatus = XMLHttpRequest.status
//                         console.log(XMLHttpRequest.status)
            if(XmlStatus==401){
                alert(XmlError.error401)
                parent.window.location.href = "../login.html"
            }
            if(XmlStatus==403){
                alert(XmlError.error403)
            }
        }
    });
}
updataEdie()
</script>
</body>
</html>